/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cognitivetest.genericTask;

import java.awt.CardLayout;

/**
 *
 * @author Libra
 */
public class GenericTasksPanel extends javax.swing.JPanel {

    /**
     * Creates new form GenericTasksPanel
     */
    public GenericTasksPanel() {
        initComponents();
        parameterCards = (CardLayout) paraPanel.getLayout();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TasksPanel = new javax.swing.JPanel();
        btnTaskCal = new javax.swing.JButton();
        paraPanel = new javax.swing.JPanel();
        pnlCalPara = new javax.swing.JPanel();
        btnCalStart = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        txtTrialNum = new javax.swing.JTextField();
        ResultPanel = new javax.swing.JPanel();

        setPreferredSize(new java.awt.Dimension(640, 600));

        TasksPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        TasksPanel.setPreferredSize(new java.awt.Dimension(340, 590));
        TasksPanel.setLayout(new java.awt.GridLayout(1, 0));

        btnTaskCal.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 14)); // NOI18N
        btnTaskCal.setText("计算");
        btnTaskCal.setPreferredSize(new java.awt.Dimension(120, 40));
        btnTaskCal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTaskCalActionPerformed(evt);
            }
        });
        TasksPanel.add(btnTaskCal);

        paraPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        paraPanel.setPreferredSize(new java.awt.Dimension(274, 300));
        paraPanel.setLayout(new java.awt.CardLayout());

        btnCalStart.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 24)); // NOI18N
        btnCalStart.setText("开始");
        btnCalStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCalStartActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 14)); // NOI18N
        jLabel11.setText("题数");

        txtTrialNum.setFont(new java.awt.Font("Microsoft YaHei UI", 0, 14)); // NOI18N
        txtTrialNum.setText("1");
        txtTrialNum.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtTrialNumActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlCalParaLayout = new javax.swing.GroupLayout(pnlCalPara);
        pnlCalPara.setLayout(pnlCalParaLayout);
        pnlCalParaLayout.setHorizontalGroup(
            pnlCalParaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCalParaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlCalParaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnCalStart, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                    .addGroup(pnlCalParaLayout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addGap(32, 32, 32)
                        .addComponent(txtTrialNum, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnlCalParaLayout.setVerticalGroup(
            pnlCalParaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlCalParaLayout.createSequentialGroup()
                .addGap(140, 140, 140)
                .addGroup(pnlCalParaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtTrialNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(btnCalStart, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        paraPanel.add(pnlCalPara, "paraCal");

        ResultPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout ResultPanelLayout = new javax.swing.GroupLayout(ResultPanel);
        ResultPanel.setLayout(ResultPanelLayout);
        ResultPanelLayout.setHorizontalGroup(
            ResultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        ResultPanelLayout.setVerticalGroup(
            ResultPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 280, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ResultPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(TasksPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(paraPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(paraPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(TasksPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ResultPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnTaskCalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTaskCalActionPerformed
        parameterCards.show(paraPanel, "paraCal");
    }//GEN-LAST:event_btnTaskCalActionPerformed

    private void btnCalStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalStartActionPerformed
//        this.setState(Frame.ICONIFIED);
        int trialNum = Integer.parseInt(txtTrialNum.getText()) * 3;
        String trialNumString = Integer.toString(trialNum);
        matSend("cd I:\\tasks\\Calculation\\");
        matSend("Calculation(1,1," + trialNumString + ");");
        returnUI(3);
    }//GEN-LAST:event_btnCalStartActionPerformed

    private void matSend(String s) {
        cognitivetest.toolLibs.MatlabControlInterface.send(s);
    }

    private void returnUI(int time) {
        cognitivetest.toolLibs.MatlabControlInterface.returnUI(time);
    }


    private void txtTrialNumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtTrialNumActionPerformed

    }//GEN-LAST:event_txtTrialNumActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ResultPanel;
    private javax.swing.JPanel TasksPanel;
    private javax.swing.JButton btnCalStart;
    private javax.swing.JButton btnTaskCal;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JPanel paraPanel;
    private javax.swing.JPanel pnlCalPara;
    private javax.swing.JTextField txtTrialNum;
    // End of variables declaration//GEN-END:variables

    final private CardLayout parameterCards;

}
